<template>
    <div>
        <login-top middleTop="登录管理平台">
            <div slot="right"
            style="font-size:3.611vw"
            @click="$router.push('/register')">
            点击注册
            </div>
        </login-top>
        <login-text label="账号"
         v-model="user.username"
         style="margin:4.167vw 0;"
         placeholder="请输入账号"
         @inputChange="inputChange"
        />
        <login-text label="密码"
         v-model="user.password"
         placeholder="请输入密码"
         type="password"
         @inputChange="inputChange1"
        />
        <login-btn btntext="登录" :method="login1"></login-btn>
    </div>
</template>
<script>
import LoginTop from '../components/common/LoginTop.vue'
import LoginText from '../components/common/LoginText.vue'
import LoginBtn from '../components/common/LoginBtn.vue'
import Cookie from 'js-cookie'
import { Toast } from 'vant'
import {login} from '../api/login'
import router from '../router'
export default{
  data () {
    return {
      user: {
        username: '',
        password: ''
      }
    }
  },
  components: {
    LoginTop,
    LoginText,
    LoginBtn
  },
  methods: {
    // 用户名
    inputChange (e) {
      this.user.username = e
    },
    // 密码
    inputChange1 (e) {
      this.user.password = e
    },
    login1 () {
      // 这里密码用户名最好是jsonobject格式的
      login(this.user).then(response => {
        // console.log(response)
        if (response.code === 200) {
          Cookie.set('token', response.data)
          router.push({path: '/home'})
        } else {
          Toast.fail(response.message)
        }
      })
    }
  }
}
</script>
<style scoped>

</style>
